var btn = document.getElementById("btn");
var username = document.getElementById("username");
var password = document.getElementById("password");
var rpassword = document.getElementById("rpassword");


btn.onclick = async function () {
  
  let url = "http://127.0.0.1:8888/users/register";
  let options = {
      method: "POST",
      headers: {
              "Content-Type": "application/x-www-form-urlencoded"
      },
      body: `username=${username.value}&password=${password.value}&rpassword=${rpassword.value}&nickname='kid'`
  };

  let response = await fetch(url, options);
  let data = await response.json();

  console.log(data);

  if (data.code === 1) {
      alert("注册成功，请进行登录");
      setTimeout(function () {
              location.href = "log in.html";
      }, 1000)
  } else {
      alert(data.message);
  }
}